const express=require("express");
var router=express.Router();
var pool=require("../pool");
//出版图书  左边
router.get("/indexread/:bid",(req,res)=>{
  var bid=req.params.bid
  var sql="SELECT * FROM mx_book where bid=?";
  pool.query(sql,[bid],(err,result)=>{
    if(err){
      console.log(err);
    }
    // res.writeHead(200,{
    //   "Access-Control-Allow-Origin":"http://127.0.0.1:5500"
    // });
    // res.write(JSON.stringify(result));
    // res.end();
    res.send(result);
	console.log(result);
  })
})

//出版图书 中间
router.get('/mlist/:pno',(req,res,next)=>{
  let pno=req.params.pno;
  console.log(pno)
  // let count=Number(obj.count);
  pool.query('select * from mx_book limit ?,4',[(pno-1)*4],(err,result)=>{
      if (err)
      {
          next(err);
          return;
      }
      console.log(result);
      //判断是否查到
      if (result.length==0)
      {
          res.send({code:200,msg:'查询失败'});
      }else{
          res.send({code:201,msg:'查询成功',data:result});
      };
  });
})

//出版图书  右边
router.get('/rlist/:pno',(req,res,next)=>{
  let pno=req.params.pno;
  console.log(pno)
  // let count=Number(obj.count);
  pool.query('select * from mx_book limit ?,10',[(pno-1)*10],(err,result)=>{
      if (err)
      {
          next(err);
          return;
      }
      console.log(result);
      //判断是否查到
      if (result.length==0)
      {
          res.send({code:200,msg:'查询失败'});
      }else{
          res.send({code:201,msg:'查询成功',data:result});
      };
  });
})

//男频 女频中间
router.get('/plist/:pno',(req,res,next)=>{
  let pno2=req.params.pno;
  console.log(pno2)
  // let count=Number(obj.count);
  pool.query('select * from mx_book limit ?,6',[(pno2-1)*6],(err,result)=>{
      if (err)
      {
          next(err);
          return;
      }
      console.log(result);
      //判断是否查到
      if (result.length==0)
      {
          res.send({code:200,msg:'查询失败'});
      }else{
          res.send({code:201,msg:'查询成功',data:result});
      };
  });
})
module.exports=router;
//http://localhost:3000/index
 